package org.jeecg.modules.cascv.image.tools;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.HexUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;

/**
 * @author;作者
 * @Date 2023/4/27 10:26
 * @Description :
 * @Version
 */
public class GaowencailiaoUDP {
    public static void main(String[] args) throws Exception {
        byte[] bytes = FileUtil.readBytes("E:\\图像数据\\cut\\高温\\" +
                "TGMT_HTMR_XRSD_SCI_20221029200044_20221029200044_0_0_L0_V1.dat");
        String s = HexUtil.encodeHexStr(bytes);
        String[] split = s.split("55aa");
        JSONObject jsonObject = new JSONObject();

        for (String s1 : split) {
            if (StringUtils.isEmpty(s1)) {
                continue;
            }
            String data = "55aa" + s1;
            Integer startAndPackageNo = Integer.parseUnsignedInt(data.substring(12, 16), 16);
            // 1111 1111 1111 1111
            // 0011 1111 1111 1111

            int startFlag = startAndPackageNo >>> 14;
            String substring = data.substring(32, data.length() - 4);

            Long second = Long.parseUnsignedLong(data.substring(16, 22), 16);

            Long subSecond = Long.parseUnsignedLong(data.substring(22, 26), 16);
            String startFlagStr = Integer.toBinaryString(startFlag);
            if(startFlag==1||startFlag==0){
                startFlagStr="0"+startFlagStr;
            }
            jsonObject.put("tableName", "6D1DH_27H_UDP");
            jsonObject.put("APED_APDATA_0_2005_1", substring);
            jsonObject.put("APED_APHEAD_6_7_1",startFlagStr+"B;"+startFlagStr+"B;序列标识");

            jsonObject.put("second", second);
            jsonObject.put("subsecond", subSecond);
            FileUtil.appendUtf8String(jsonObject.toString() + System.lineSeparator(),
                    "E:\\图像数据\\cut\\高温\\" +
                            "TGMTYY1401_09CH_31_TPSRAPP1UDP_1.txt");
        }
    }
}
